import Vue from 'vue'
import VueRouter from 'vue-router'
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
   return originalPush.call(this, location).catch(err => err)
}
const originalReplace = VueRouter.prototype.replace;
VueRouter.prototype.replace = function replace(location) {
    return originalReplace.call(this, location).catch(err => err);
};
//按需加载组件（懒加载）
const Home = () => import('views/home/Home')
const Category = () => import('views/category/Category')
const Cart = () => import('views/cart/Cart')
const Profile = () => import('views/profile/Profile')
const Detail = () => import('views/detail/Detail')
//1.安装VueRouter
Vue.use(VueRouter)

const routes = [
 {
   path:'/',
   redirect:'/home'
 },
 {
   path:'/home',
   component:Home,
  //  children: [
  //   {
  //     path:'goods/:type',
  //     component:GoodList,
  //   },
  //  ]
 },
 {
   path:'/detail/:id',
   component: Detail,
   props: true
 },
 {
   path:'/category',
   component:Category
 },
 {
   path:'/cart',
   component:Cart
 },
 {
   path:'/Profile',
   component:Profile
 },{
   path:'detail',
   component:Detail
 }

]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes,
  linkActiveClass:'active'
})

export default router
